//
//  DetailViewcontroller.m
//  FanTest
//
//  Created by Cheng on 12/6/28.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import <Twitter/Twitter.h>
#import <Accounts/Accounts.h>
#import "HomePageViewController.h"
#import "DetailViewController.h"
#import "DetailMyBoardUIViewController.h"
#import "MediaListsMedia.h"
#import "ClipToMyBoardView.h"
#import "AccountInfo.h"
#import "AccountMyBoard.h"
#import "AppDelegate.h"
#import "Crop.h"
#import "RequestAPIFunction.h"
#import "WebViewController.h"
#import "Split.h"
#import "LoadingUI.h"

#define IMAGE_FRAME_VERTICAL_XAIS_X 20
#define IMAGE_FRAME_VERTICAL_WIDTH_LIMIT 551
#define IMAGE_FRAME_VERTICAL_HEIGHT_LIMIT 642
#define DESCRIPTION_VERTICAL_XAIS_X 581
#define DESCRIPTION_VERTICAL_XAIS_Y 40
#define DESCRIPTION_VERTICAL_WIDTH 385
#define DESCRIPTION_VERTICAL_HEIGHT 578
#define DESCRIPTION_VERTICAL_MAX 1100

#define LOGO_HORIZONTAL_XAIS_Y 500
#define IMAGE_FRAME_HORIZONTAL_WIDTH_LIMIT 984
#define IMAGE_FRAME_HORIZONTAL_HEIGHT_LIMIT 439
#define DESCRIPTION_HORIZONTAL_XAIS_X 44
#define DESCRIPTION_HORIZONTAL_XAIS_Y 532
#define DESCRIPTION_HORIZONTAL_WIDTH 950
#define DESCRIPTION_HORIZONTAL_HEIGHT 110
#define DESCRIPTION_HORIZONTAL_MAX 200

#define ONLY_DESCRIPTION_XAIS_X 62
#define ONLY_DESCRIPTION_WIDTH 900
#define ONLY_DESCRIPTION_HEIGHT 578
#define ONLY_DESCRIPTION_MAX 2000

#define SCROLLVIEW_WIDTH 1024
#define SCROLLVIEW_HEIGHT 642
#define SCREEN_HEIGHT 768

#define WEBVIEW_ICON_AXIS_Y 63

#define COMMENT_ARROW_AXIS_X 104

#define Description_Tag 20000
#define NOTE_TAG 5000000
#define Picture_Tag 10000
#define Comment_Tag 5000
#define LOADINGVIEW_TAG 10000000
#define LOADINGIMAGE_TAG 20000000

#define MEDIA_TAG 200000
#define IMAGETAG_TAG 100000

#define DEFAULT_CONTENT @"Write your comment here."

#define BESHARE_API @"http://54.235.166.43/BeSpokeAPI/Sharing/beShare.php"
#define BESHARE_HTML_API @"http://54.235.166.43/BeSpokeAPI/Sharing/beShare_Html.php"

@implementation DetailViewController

@synthesize MLM_detail,AI_accountDetail,MLI_images;
@synthesize Lab_DeatilTitle, Lab_SourceAndAuthor, WVw_description, IVw_Image, IVw_Logo, WVw_GoogleFeed;
@synthesize BK_En_object, ActivityView, Bt_SavetoMyboard, PageNum;
@synthesize Vw_Share, Vw_addClip, SV_Detail, Check_Description_Index, Vw_Notes, Bt_NoteShowOrHide;
@synthesize Vw_Comment, Bt_Comment, Bt_ShowWeb, Bt_AddComment, Vw_CreateBook, IVw_Tag;
@synthesize delegate;

int Text_DescriptionLength=0;

-(IBAction)goback:(id)sender
{
    if  (([sender isKindOfClass:[UIButton class]])||
        (([sender isKindOfClass:[UIPinchGestureRecognizer class]])&&
         (((UIPinchGestureRecognizer *)sender).state==UIGestureRecognizerStateEnded)&&
         ([self.view viewWithTag:NOTE_TAG]==nil))) {
            [self.delegate DetailViewControllerDidClose:self];
        }
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSLog(@"%@",[MLM_detail.MLH_html.NS_htmlDescription StringParseSymbol]);
    PageNum = 0;
    Check_Description_Index = 0;
    
    //Add Gesture.
    UIRotationGestureRecognizer *LongPress = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(NotesPressed:)];
    UIPinchGestureRecognizer *PinchPress = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(goback:)];
    
    //Check previous controller.
    if ([self.delegate isKindOfClass:[HomePageViewController class]]) {
        
        [NSThread detachNewThreadSelector:@selector(CheckMediaInBookPressed) toTarget:self withObject:nil];
        
        if ([MLM_detail.NS_Source isEqualToString:@"TPN"]) {
            
            self.Bt_Comment.hidden = NO;
            self.Bt_AddComment.hidden = NO;
            [Bt_Comment setTitle:[NSString stringWithFormat:@"%d",MLM_detail.Array_Comment.count] forState:UIControlStateNormal];
            
            //Rotate Gesture.
            [SV_Detail addGestureRecognizer:LongPress];
            LongPress.delegate = self;
            if (MLM_detail.MLH_html.NS_htmlTitle!=nil) {
                
                LongPress.cancelsTouchesInView = NO;
                [WVw_GoogleFeed.scrollView addGestureRecognizer:LongPress];
            }
            
            if ((MLM_detail.Array_Notes.count!=0)&&(Bt_NoteShowOrHide.hidden==YES))
                Bt_NoteShowOrHide.hidden = NO;
        }
    }
    else if ([self.delegate isKindOfClass:[DetailMyBoardUIViewController class]]) {
        
        self.Bt_SavetoMyboard.hidden = YES;
        self.Bt_Comment.hidden = NO;
        self.Bt_AddComment.hidden = NO;
        [Bt_Comment setTitle:[NSString stringWithFormat:@"%d",MLM_detail.Array_Comment.count] forState:UIControlStateNormal];
        
        
        //Rotate Gesture.
        [SV_Detail addGestureRecognizer:LongPress];
        LongPress.delegate = self;
        if (MLM_detail.MLH_html.NS_htmlTitle!=nil) {
            
            LongPress.cancelsTouchesInView = NO;
            [WVw_GoogleFeed.scrollView addGestureRecognizer:LongPress];
        }
        
        if ((MLM_detail.Array_Notes.count!=0)&&(Bt_NoteShowOrHide.hidden==YES))
            Bt_NoteShowOrHide.hidden = NO;
    }
    
    
    self.IVw_Logo.image = [[UIImage alloc] initWithContentsOfFile:[LoadingUI IconPressed:MLM_detail.NS_Source]];
    float ratio = IVw_Logo.image.size.width/32;
    self.IVw_Logo.image =
    [UIImage imageWithCGImage:[IVw_Logo.image CGImage]
                        scale:ratio orientation:UIImageOrientationUp];
    //Paragraph.
    MLM_detail.text.text_description = [MLM_detail.text.text_description stringByReplacingOccurrencesOfString:@".     " withString:@".<br></br>   "];
    MLM_detail.text.text_description = [MLM_detail.text.text_description stringByReplacingOccurrencesOfString:@".    " withString:@".<br></br>   "];
    MLM_detail.text.text_description = [MLM_detail.text.text_description stringByReplacingOccurrencesOfString:@".   " withString:@".<br></br>   "];
    MLM_detail.text.text_description = [MLM_detail.text.text_description stringByReplacingOccurrencesOfString:@".  " withString:@".<br></br>   "];

    
    //Image is not empty.
    if (MLM_detail.imageArray.count!=0) {
    
        for (int i = 0; i < MLM_detail.imageArray.count; i++) {
            
            MLI_images = [MLM_detail.imageArray objectAtIndex:i];
            
            //Check image
            if (([MLI_images.image_filename rangeOfString:@"safe_image.php"].location != NSNotFound)||
                ([MLI_images.image_filename rangeOfString:@"app_full_proxy.php"].location != NSNotFound)) {
                
                [MLM_detail.imageArray removeObject:MLI_images];
                [self DescriptionPage:ONLY_DESCRIPTION_MAX];
                [ActivityView stopAnimating];
                return;
            }
            
            NSString *string = [NSString stringWithFormat:@"%@",MLI_images.image_filename];
            NSURL *url = [NSURL URLWithString:string];
            
            SDWebImageManager *manager = [SDWebImageManager sharedManager];
            [manager downloadWithURL:url delegate:self options:0 success:^(UIImage *image) {
                
                [ActivityView stopAnimating];
                
                PageNum ++;
                
                NSLog(@"Page:%d",PageNum);
                
                if (PageNum==MLM_detail.imageArray.count) {
                    
                    for (MediaListsNote *MLN_Note in MLM_detail.Array_Notes)
                        [self SetAxisX:MLN_Note.Axis_X SetAxisY:MLN_Note.Axis_Y SetIndex:[MLM_detail.Array_Notes indexOfObject:MLN_Note]];
                }
                
                if (image.size.height>image.size.width)
                    [self DescriptionPage:DESCRIPTION_VERTICAL_MAX];
                else
                    [self DescriptionPage:DESCRIPTION_HORIZONTAL_MAX];
                
                SV_Detail.contentSize = CGSizeMake(SV_Detail.frame.size.width, PageNum*self.SV_Detail.frame.size.height);
            }failure:^(NSError *error) {
                [ActivityView stopAnimating];
            }];
        }
        
        Lab_DeatilTitle.text = MLM_detail.text.text_title;
        
        
        [SV_Detail addGestureRecognizer:PinchPress];
        PinchPress.delegate = self;
        
    }
    else if (MLM_detail.MLH_html.NS_htmlTitle==nil) {
        [ActivityView stopAnimating];
        
        Lab_DeatilTitle.text = MLM_detail.text.text_title;
        
        [self DescriptionPage:ONLY_DESCRIPTION_MAX];
        
        for (MediaListsNote *MLN_Note in MLM_detail.Array_Notes)
            [self SetAxisX:MLN_Note.Axis_X SetAxisY:MLN_Note.Axis_Y SetIndex:[MLM_detail.Array_Notes indexOfObject:MLN_Note]];
        
        [SV_Detail addGestureRecognizer:PinchPress];
        PinchPress.delegate = self;
    }
    else if (MLM_detail.MLH_html.NS_htmlTitle!=nil) {
        
        //Get Source And Author.
        NSMutableString *NS_SourceAndAuthor = [NSMutableString stringWithString:MLM_detail.NS_Source];
        if (![MLM_detail.NS_Author isEqualToString:@""])
            [NS_SourceAndAuthor appendFormat:@"//%@",MLM_detail.NS_Author];
        Lab_SourceAndAuthor.text = NS_SourceAndAuthor;
        IVw_Logo.frame = CGRectMake(WVw_GoogleFeed.frame.origin.x+6,
                                    0,
                                    IVw_Logo.frame.size.width,
                                    IVw_Logo.frame.size.height);
        Lab_SourceAndAuthor.frame = CGRectMake(IVw_Logo.frame.origin.x+IVw_Logo.frame.size.width+5,
                                               IVw_Logo.center.y-Lab_SourceAndAuthor.frame.size.height/2,
                                               Lab_SourceAndAuthor.frame.size.width,
                                               Lab_SourceAndAuthor.frame.size.height);
        IVw_Logo.hidden = NO;
        Lab_SourceAndAuthor.hidden = NO;
        
        [WVw_GoogleFeed loadHTMLString:[NSString stringWithFormat:@"<html><body>%@</body></html>",MLM_detail.MLH_html.NS_htmlDescription] baseURL:nil];
        
        //Clean Scroll Shadow.
        for (UIView *subview in [WVw_GoogleFeed.scrollView subviews])
            if ([subview isKindOfClass:[UIImageView class]])
                subview.hidden = YES;
        
        Bt_ShowWeb.hidden = NO;
        
        WVw_GoogleFeed.delegate = self;
        [WVw_GoogleFeed setHidden:NO];
        [WVw_GoogleFeed setOpaque:NO];
        [self.view bringSubviewToFront:WVw_GoogleFeed];
        
        PinchPress.cancelsTouchesInView = NO;
        [WVw_GoogleFeed.scrollView addGestureRecognizer:PinchPress];
        
        [ActivityView stopAnimating];
        
        SV_Detail=nil;
        [SV_Detail removeFromSuperview];
        
        for (MediaListsNote *MLN_Note in MLM_detail.Array_Notes)
            [self SetAxisX:MLN_Note.Axis_X SetAxisY:MLN_Note.Axis_Y SetIndex:[MLM_detail.Array_Notes indexOfObject:MLN_Note]];
        
        Lab_DeatilTitle.text = MLM_detail.MLH_html.NS_htmlTitle;
    }
}

-(IBAction)clipToMyBoard:(id)sender {
    
    self.SV_Detail.userInteractionEnabled = NO;
    
    if(Vw_addClip == nil) {
        
        [[NSBundle mainBundle] loadNibNamed:@"ClipToMyBoardView" owner:self options:nil];//Create Clip view.
        Vw_addClip.frame = CGRectMake(self.view.bounds.size.width/2-self.Vw_addClip.IVw_Background.frame.size.width/2,
                                      self.view.bounds.size.height/2-self.Vw_addClip.IVw_Background.frame.size.height/2,
                                      self.Vw_addClip.frame.size.width,
                                      self.Vw_addClip.frame.size.height);
        
        Vw_addClip.MM_CurrentMedia = self.MLM_detail;
        Vw_addClip.BK_En_object = self.BK_En_object;
        Vw_addClip.delegate = self;
    }
    [self.Vw_addClip initArray:self.AI_accountDetail.MyBoard.BoardArray];
    [Vw_addClip setAlpha:0];
    
    //Add Clip view to self.view.
    [UIView animateWithDuration:0.3
                     animations:^{[Vw_addClip setAlpha:1.0];[self.view addSubview:Vw_addClip];}
                     completion:^(BOOL finished){ }];
}


- (IBAction)HideNotePressed:(id)sender {
    [self.Bt_NoteShowOrHide setImage:[UIImage imageNamed:@"btn_shownotes.png"] forState:UIControlStateNormal];
    [self.Bt_NoteShowOrHide removeTarget:sender action:@selector(HideNotePressed:) forControlEvents:UIControlEventTouchUpInside];
    [self.Bt_NoteShowOrHide addTarget:self action:@selector(ShowNotePressed:) forControlEvents:UIControlEventTouchUpInside];
    
    //Search Note in ScrollView.
    UIScrollView *SVw_Main;
    
    if (self.SV_Detail==nil)
        SVw_Main = self.WVw_GoogleFeed.scrollView;
    else
        SVw_Main = self.SV_Detail;
    
    for (UIView *Bt_Note in SVw_Main.subviews)
        if([Bt_Note isKindOfClass:[UIButton class]])
            Bt_Note.hidden = YES;
}

- (void)ShowNotePressed:(id)sender {
    [self.Bt_NoteShowOrHide setImage:[UIImage imageNamed:@"btn_hidenotes.png"] forState:UIControlStateNormal];
    [self.Bt_NoteShowOrHide removeTarget:sender action:@selector(ShowNotePressed:) forControlEvents:UIControlEventTouchUpInside];
    [self.Bt_NoteShowOrHide addTarget:self action:@selector(HideNotePressed:) forControlEvents:UIControlEventTouchUpInside];
    
    //Search Note in ScrollView.
    UIScrollView *SVw_Main;
    
    if (self.SV_Detail==nil)
        SVw_Main = self.WVw_GoogleFeed.scrollView;
    else
        SVw_Main = self.SV_Detail;
    
    for (UIView *Bt_Note in SVw_Main.subviews)
        if([Bt_Note isKindOfClass:[UIButton class]])
            Bt_Note.hidden = NO;
}

- (void)NotesPressed:(id)sender {
    
    
    if (Vw_Notes == nil) {
        //Create Notes view.
        [[NSBundle mainBundle] loadNibNamed:@"EditNotes" owner:self options:nil];
        
        Vw_Notes.center = CGPointMake(self.view.bounds.size.width/2, self.view.bounds.size.height/2);
        Vw_Notes.tag = NOTE_TAG;
        Vw_Notes.BK_En_object = self.BK_En_object;
        Vw_Notes.delegate = self;
        
        //Check Media is in MyBooks.
        NSMutableArray *Array_Book = self.AI_accountDetail.MyBoard.BoardArray;
        for (AccountBoard *AB_Book in Array_Book)
            for (MediaListsMedia *Media_InBook in AB_Book.MediaArray)
                if (((Media_InBook.MediaID==MLM_detail.MediaID)&&([Media_InBook.NS_Source isEqualToString:@"TPN"])&&([MLM_detail.NS_Source isEqualToString:@"TPN"])&&(MLM_detail!=Media_InBook))||
                    (([Media_InBook.NS_BeMediaID isEqualToString:MLM_detail.NS_BeMediaID])&&(![MLM_detail.NS_Source isEqualToString:@"TPN"])&&(MLM_detail!=Media_InBook))) {
                    Vw_Notes.MLM_Detail.Array_Comment = Media_InBook.Array_Comment;
                }
    }
    
    
    if([sender isKindOfClass:[UIButton class]]) {
        
        [Vw_Notes.TVw_Content setEditable:NO];
        Vw_Notes.TVw_Content.text = ((MediaListsNote *)[MLM_detail.Array_Notes objectAtIndex:((UIButton *)sender).tag]).NS_NoteText;
        Vw_Notes.MLM_Detail = self.MLM_detail;
        Vw_Notes.AxisX = ((UIButton *)sender).center.x;
        Vw_Notes.AxisY = ((UIButton *)sender).center.y;
        Vw_Notes.Note_Index = ((UIButton *)sender).tag;
        
        [Vw_Notes setAlpha:0];
        
        //Add Note view to self.view.
        [UIView animateWithDuration:0.3
                         animations:^{[Vw_Notes setAlpha:1.0];[self.view addSubview:Vw_Notes];}
                         completion:^(BOOL finished){ }];
    }
    else if (((UIRotationGestureRecognizer *)sender).state == UIGestureRecognizerStateBegan) {
        
        UIRotationGestureRecognizer *paramSender = (UIRotationGestureRecognizer *)sender;
        CGPoint touchPoint = [paramSender locationInView:paramSender.view];
        
        [Vw_Notes.TVw_Content setEditable:NO];
        Vw_Notes.TVw_Content.text = nil;
        Vw_Notes.MLM_Detail = self.MLM_detail;
        
        
        Vw_Notes.AxisX = touchPoint.x;
        Vw_Notes.AxisY = touchPoint.y;
        
        Vw_Notes.Note_Index = -1;
        
        [Vw_Notes setAlpha:0];
        
        //Add Note view to self.view.
        [UIView animateWithDuration:0.3
                         animations:^{[Vw_Notes setAlpha:1.0];[self.view addSubview:Vw_Notes];}
                         completion:^(BOOL finished){ }];
    }
}

- (IBAction)CommentPressed:(id)sender {
    
    if (Vw_Comment == nil) {
        [[NSBundle mainBundle] loadNibNamed:@"CommentView" owner:self options:nil];

        Vw_Comment.frame = CGRectMake(Bt_AddComment.center.x-COMMENT_ARROW_AXIS_X,
                                      Bt_AddComment.frame.origin.y-Vw_Comment.frame.size.height,
                                      Vw_Comment.frame.size.width,
                                      Vw_Comment.frame.size.height);
        Vw_Comment.MLM_Detail = self.MLM_detail;
        Vw_Comment.BK_En_object = self.BK_En_object;
        Vw_Comment.TVw_AddContent.delegate = self.Vw_Comment;
        Vw_Comment.delegate = self;
        [Vw_Comment initialize];
        
        //Check Media is in MyBooks.
        NSMutableArray *Array_Book = self.AI_accountDetail.MyBoard.BoardArray;
        for (AccountBoard *AB_Book in Array_Book)
            for (MediaListsMedia *Media_InBook in AB_Book.MediaArray)
                if (((Media_InBook.MediaID==MLM_detail.MediaID)&&([Media_InBook.NS_Source isEqualToString:@"TPN"])&&([MLM_detail.NS_Source isEqualToString:@"TPN"])&&(MLM_detail!=Media_InBook))||
                    (([Media_InBook.NS_BeMediaID isEqualToString:MLM_detail.NS_BeMediaID])&&(![MLM_detail.NS_Source isEqualToString:@"TPN"])&&(MLM_detail!=Media_InBook))) {
                    Vw_Comment.MLM_Detail.Array_Comment = Media_InBook.Array_Comment;
                }
    }
    
    [Vw_Comment CalculateDateTime];
    Vw_Comment.TVw_AddContent.text = DEFAULT_CONTENT;
    Vw_Comment.TVw_AddContent.textColor = [UIColor lightGrayColor];
    [Vw_Comment setAlpha:0];
    
    //Add Note view to self.view.
    [UIView animateWithDuration:0.3
                     animations:^{[Vw_Comment setAlpha:1.0];[self.view addSubview:Vw_Comment];}
                     completion:^(BOOL finished){ }];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    
    WebViewController *VC_detail = segue.destinationViewController;
    VC_detail.MLM_webView = MLM_detail;
}

#pragma mark - Interface Orientation Management

//For iOS 5
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
	return ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight));
}

//For iOS 6
-(BOOL)shouldAutorotate {
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}

#pragma mark -
#pragma mark Share Function

-(IBAction)sharePressed:(id)sender
{
    if(Vw_Share == nil)
    {
        /**NSMutableArray *Array_ShareMedia = [[NSMutableArray alloc] init];
        
        NSMutableArray *Array_MyGroups = [[NSMutableArray alloc] init];
        [Array_MyGroups addObject:@"Bridesmaids"];
        [Array_MyGroups addObject:@"Wedding Party"];
        [Array_MyGroups addObject:@"Make public"];
        [Array_MyGroups addObject:@"Add Group"];
        //[Array_MyGroups addObject:nil];
        
        [Array_ShareMedia addObject:Array_MyGroups];**/
        
        NSMutableArray* Array_Social = [[NSMutableArray alloc] init];
        [Array_Social addObject:@"Facebook"];
        [Array_Social addObject:@"Twitter"];
        [Array_Social addObject:@"Send email"];
        //[Array_Social addObject:nil];
        self.navigationItem.title = @"Countries";
        //[Array_ShareMedia addObject:Array_Social];

        [[NSBundle mainBundle] loadNibNamed:@"ShareMedia" owner:self options:nil];//Create Clip view.
        [Vw_Share setBackgroundColor:nil];
        
        Vw_Share.center = CGPointMake(((UIButton *)sender).center.x, ((UIButton *)sender).frame.origin.y-Vw_Share.frame.size.height/2);
        //Vw_Share.frame = CGRectMake(((UIButton *)sender).center.x, 377,Vw_Share.frame.size.width,Vw_Share.frame.size.height );
        [Vw_Share OptionArray:Array_Social];
        Vw_Share.delegate = self;
        
    }
    [Vw_Share setAlpha:0];
    [UIView animateWithDuration:0.5
                     animations:^{[Vw_Share setAlpha:1.0];[self.view addSubview:Vw_Share];}
                     completion:^(BOOL finished){ }];
}

- (void)openFacebook
{
    
    if (([BK_En_object.NS_FaceBookID isEqualToString:@""])||(BK_En_object.NS_FaceBookID==nil)) {
        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"Alert" message:@"Please set up your Facebook account in your Personal settings?" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
        [alertView show];
        return;
    }
    
    NSString *NS_ImageURL = @"";
    NSData *responseData;
    
    if (MLM_detail.imageArray.count!=0) {
        NS_ImageURL = ((MediaListsImage *)[MLM_detail.imageArray objectAtIndex:0]).image_filename;
    }
    
    
    
    
    if ([self.MLM_detail.MediaType isEqualToString:@"Camera"])
        responseData =
        [RequestAPIFunction XML_PostRequest:[[NSString stringWithFormat:@"<ShareInfo UserName=\"%@\" MediaID=\"\" Title=\"%@\" Description=\"%@\" WebLink=\"%@\" ImageURL=\"%@\" MediaType=\"%@\"><facebook ID=\"%@\" token=\"%@\" /><twitter key=\"\" secret=\"\" /><instagram token=\"\" /></ShareInfo>",
                                             BK_En_object.userName,
                                             Lab_DeatilTitle.text,
                                             Lab_DeatilTitle.text,
                                             MLM_detail.WebLink,
                                             NS_ImageURL,
                                             MLM_detail.MediaType,
                                             BK_En_object.NS_FaceBookID,
                                             BK_En_object.NS_FaceBookToken] stringByReplacingOccurrencesOfString:@"&" withString:@"&amp;"]
                                  urlString:BESHARE_API ImageData:UIImageJPEGRepresentation(IVw_Image.image, 1.0)];
    else
        responseData =
        [RequestAPIFunction XML_PostRequest:[[NSString stringWithFormat:@"<ShareInfo UserName=\"%@\" MediaID=\"\" Title=\"%@\" Description=\"%@\" WebLink=\"%@\" ImageURL=\"%@\" MediaType=\"%@\"><facebook ID=\"%@\" token=\"%@\" /><twitter key=\"\" secret=\"\" /><instagram token=\"\" /></ShareInfo>",
                                             BK_En_object.userName,
                                             Lab_DeatilTitle.text,
                                             Lab_DeatilTitle.text,
                                             MLM_detail.WebLink,
                                             NS_ImageURL,
                                             MLM_detail.MediaType,
                                             BK_En_object.NS_FaceBookID,
                                             BK_En_object.NS_FaceBookToken] stringByReplacingOccurrencesOfString:@"&" withString:@"&amp;"]
                                  urlString:BESHARE_HTML_API];
        
    //No Network Connection or time out.
    if (responseData == nil)
        return;
    
    NSString *result = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
    
    if ([result rangeOfString:@"Success"].location != NSNotFound) {

        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"Success"
                                                           message:@"Facebook has been shared!"
                                                          delegate:nil
                                                 cancelButtonTitle:@"Ok"
                                                 otherButtonTitles:nil];
        [alertView show];
    }
    else {
        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"Alert"
                                                           message:result
                                                          delegate:nil
                                                 cancelButtonTitle:@"Ok"
                                                 otherButtonTitles:nil];
        [alertView show];
    }
}

- (void)openTwitter 
{
    if ([TWTweetComposeViewController canSendTweet]) {
        TWTweetComposeViewController *twitterComposer = [[TWTweetComposeViewController alloc]init];
        
        if ((![Lab_DeatilTitle.text isEqualToString:@""])&&(Lab_DeatilTitle.text!=nil))
            [twitterComposer setInitialText:[NSString stringWithFormat:@"%@ - %@",Lab_DeatilTitle.text,MLM_detail.NS_Source]];
        else
            [twitterComposer setInitialText:[NSString stringWithFormat:@"%@",MLM_detail.NS_Source]];
        
        if (MLM_detail.imageArray.count!=0)
            [twitterComposer addImage:((UIImageView *)[SV_Detail viewWithTag:Picture_Tag]).image];
        else if (MLM_detail.MLH_html.NS_ImageName!=nil) {
            
            
            NSURL *url = [NSURL URLWithString:[NSString stringWithString:MLM_detail.MLH_html.NS_ImageName]];
            
            NSData *data = [NSData dataWithContentsOfURL:url];
            UIImage *img = [[UIImage alloc] initWithData:data];
            
            [twitterComposer addImage:img];
        }
        else
            [twitterComposer addURL:[NSURL URLWithString:MLM_detail.WebLink]];
    
    
        [self presentModalViewController:twitterComposer animated:YES];
    
        //check to update the user regarding his tweet
        twitterComposer.completionHandler = ^(TWTweetComposeViewControllerResult res){
        
        //if the posting is done successfully
            if (res == TWTweetComposeViewControllerResultDone){
                UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"Success" message:@"Tweet has been shared!" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
                [alertView show];
            }
            //dismiss the twitter modal view controller.
            [self dismissViewControllerAnimated:YES completion:nil];
        };
    }
    else if (![TWTweetComposeViewController canSendTweet]) {
        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"Alert" message:@"Please set up your Twitter account in your Personal settings?" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
        [alertView show];
    }
}
- (void)openMail 
{
    if ([MFMailComposeViewController canSendMail])
    {
        MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
        
        mailer.mailComposeDelegate = self;
        
        if (([Lab_DeatilTitle.text isEqualToString:@""])||(Lab_DeatilTitle.text == nil)) {
            [mailer setSubject:@"Article"];
            Lab_DeatilTitle.text  = @"";
        }
        else
            [mailer setSubject:[NSString stringWithFormat:@"Article:%@",Lab_DeatilTitle.text]];
        
        NSString *WebLink_Temp;
        
        WebLink_Temp = MLM_detail.WebLink;
        
        if (([MLM_detail.WebLink isEqualToString:@""])||(MLM_detail.WebLink == nil)) {
            WebLink_Temp = @"";
        }
        
        NSArray *toRecipients = [NSArray arrayWithObjects:@"", nil];
        [mailer setToRecipients:toRecipients];
        
        [mailer setMessageBody:[NSString stringWithFormat:@"<b>%@</b><br><a href='%@'>%@</a></br><br>Send via TPN</br>",Lab_DeatilTitle.text, WebLink_Temp, WebLink_Temp] isHTML:YES];
        
        if (IVw_Image.image!=nil) {
            NSData *imageData = UIImagePNGRepresentation(IVw_Image.image);
            [mailer addAttachmentData:imageData mimeType:@"image/png" fileName:@"iPad_Image"];
        }
        
        [self presentModalViewController:mailer animated:YES];
                
    }
    else
    {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Failure"
                                                            message:@"Your device doesn't support the composer sheet"
                                                           delegate:nil
                                                  cancelButtonTitle:@"OK"
                                                  otherButtonTitles:nil];
        [alertView show];
    }
    
}

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{   
    switch (result)
    {
        case MFMailComposeResultCancelled:
            NSLog(@"Mail cancelled: you cancelled the operation and no email message was queued.");
            break;
        case MFMailComposeResultSaved:
            NSLog(@"Mail saved: you saved the email message in the drafts folder.");
            break;
        case MFMailComposeResultSent:
            NSLog(@"Mail send: the email message is queued in the outbox. It is ready to send.");
            break;
        case MFMailComposeResultFailed:
            NSLog(@"Mail failed: the email message was not saved or queued, possibly due to an error.");
            break;
        default:
            NSLog(@"Mail not sent.");
            break;
    }
    
    // Remove the mail view
    [self dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark - Delegate

#pragma mark ClipToMyBoardDelegate

-(void)canceltoBoardPress
{
    [Vw_addClip removeFromSuperview];
    self.SV_Detail.userInteractionEnabled = YES;
}

-(void)saveToBoardPress
{
    
    self.IVw_Tag.hidden = NO;
    [Bt_SavetoMyboard setImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"clipped" ofType:@"png"]] forState:UIControlStateNormal];
    
    [Vw_addClip removeFromSuperview];
    self.SV_Detail.userInteractionEnabled = YES;
}

-(void) CreatedNewBookPressed {
    
    [Vw_addClip removeFromSuperview];
    
    if (Vw_CreateBook == nil) {
        Vw_CreateBook = [[[NSBundle mainBundle] loadNibNamed:@"CreateBookView" owner:self options:nil] objectAtIndex:0];
        Vw_CreateBook.frame = CGRectMake(self.view.bounds.size.width/2-self.Vw_CreateBook.frame.size.width/2,
                                         self.view.bounds.size.height/2-self.Vw_CreateBook.frame.size.height/2,
                                         self.Vw_CreateBook.frame.size.width,
                                         self.Vw_CreateBook.frame.size.height);
        
        Vw_CreateBook.BK_En_object = self.BK_En_object;
        
        Vw_CreateBook.delegate = self;
        Vw_CreateBook.Tf_BookName.delegate = Vw_CreateBook;
    }
    self.SV_Detail.userInteractionEnabled = NO;
    
    Vw_CreateBook.AMB_MyBoard = self.AI_accountDetail.MyBoard;
    
    [Vw_CreateBook setAlpha:0];
    [UIView animateWithDuration:0.5
                     animations:^{[Vw_CreateBook setAlpha:1.0];[self.view addSubview:Vw_CreateBook];}
                     completion:^(BOOL finished){ }];
}

#pragma mark ShareMediaDelegate

-(void) uiViewTouched_ShareMedia:(BOOL)wasInSide
{
    if(!wasInSide) {
        [Vw_Share removeFromSuperview];
    }
}

-(void) DidSelected_Share:(NSString *)NS_ShareMedia
{
    if ([NS_ShareMedia isEqualToString:@"Facebook"]) {
        
        [NSThread detachNewThreadSelector:@selector(threadStartAnimating) toTarget:self withObject:nil];
        [self openFacebook];
        [NSThread detachNewThreadSelector:@selector(threadStopAnimating) toTarget:self withObject:nil];
    }
    else if ([NS_ShareMedia isEqualToString:@"Twitter"])
        [self openTwitter];
    else if ([NS_ShareMedia isEqualToString:@"Send email"])
        [self openMail];
}

#pragma mark SDWebImageManagerDelegate

- (void)webImageManager:(SDWebImageManager *)imageManager didFinishWithImage:(UIImage *)image 
{    
    MLI_images.Width = image.size.width;
    MLI_images.Height = image.size.height;
    
    IVw_Logo = [[UIImageView alloc] initWithImage:IVw_Logo.image];
        
    if (image.size.height>=image.size.width) {//Vertical of Style
        
        WVw_GoogleFeed = [[UIWebView alloc]initWithFrame:CGRectMake(DESCRIPTION_VERTICAL_XAIS_X,
                                                                      DESCRIPTION_VERTICAL_XAIS_Y+SV_Detail.frame.size.height*PageNum,
                                                                      DESCRIPTION_VERTICAL_WIDTH,
                                                                      DESCRIPTION_VERTICAL_HEIGHT)];
        
        IVw_Logo.frame = CGRectMake(WVw_GoogleFeed.frame.origin.x, IVw_Logo.frame.origin.y+SV_Detail.frame.size.height*PageNum, IVw_Logo.image.size.width, IVw_Logo.image.size.height);
        IVw_Logo.hidden = NO;
        
        IVw_Image = [[UIImageView alloc] initWithImage:[image SetImageSize:IMAGE_FRAME_VERTICAL_WIDTH_LIMIT Height:IMAGE_FRAME_VERTICAL_HEIGHT_LIMIT]];
        IVw_Image.frame = CGRectMake(IMAGE_FRAME_VERTICAL_XAIS_X+(IMAGE_FRAME_VERTICAL_WIDTH_LIMIT-IVw_Image.image.size.width)/2,
                                     (IMAGE_FRAME_VERTICAL_HEIGHT_LIMIT-IVw_Image.image.size.height)/2+SV_Detail.frame.size.height*PageNum,
                                     IVw_Image.image.size.width,
                                     IVw_Image.image.size.height);
        
        [self DeScription_WithImage:DESCRIPTION_VERTICAL_MAX];
    }
    else {//Horizontal of Style
        
        WVw_GoogleFeed = [[UIWebView alloc]initWithFrame:CGRectMake(DESCRIPTION_HORIZONTAL_XAIS_X,
                                                                      DESCRIPTION_HORIZONTAL_XAIS_Y+SV_Detail.frame.size.height*PageNum,
                                                                      DESCRIPTION_HORIZONTAL_WIDTH,
                                                                      DESCRIPTION_HORIZONTAL_HEIGHT)];
        
        IVw_Logo.frame = CGRectMake(WVw_GoogleFeed.frame.origin.x, LOGO_HORIZONTAL_XAIS_Y+SCROLLVIEW_HEIGHT*PageNum, IVw_Logo.image.size.width, IVw_Logo.image.size.height);
        IVw_Logo.hidden = NO;
        
        IVw_Image = [[UIImageView alloc] initWithImage:[image SetImageSize:IMAGE_FRAME_HORIZONTAL_WIDTH_LIMIT Height:IMAGE_FRAME_HORIZONTAL_HEIGHT_LIMIT]];
        IVw_Image.frame = CGRectMake((IMAGE_FRAME_HORIZONTAL_WIDTH_LIMIT-IVw_Image.image.size.width)/2,
                                     (LOGO_HORIZONTAL_XAIS_Y-IVw_Image.image.size.height)/2+SCROLLVIEW_HEIGHT*PageNum,
                                     IVw_Image.image.size.width,
                                     IVw_Image.image.size.height);
        
        [self DeScription_WithImage:DESCRIPTION_HORIZONTAL_MAX];
    }
    
    Lab_SourceAndAuthor = [[UILabel alloc] initWithFrame:CGRectMake(IVw_Logo.frame.origin.x+IVw_Logo.frame.size.width+5,
                                                                    IVw_Logo.center.y-21/2,
                                                                    386,
                                                                    21)];
    NSMutableString *NS_SourceAndAuthor = [NSMutableString stringWithString:MLM_detail.NS_Source];
    if (![MLM_detail.NS_Author isEqualToString:@""])
        [NS_SourceAndAuthor appendFormat:@"//%@",MLM_detail.NS_Author];
    Lab_SourceAndAuthor.backgroundColor = [UIColor clearColor];
    Lab_SourceAndAuthor.text = NS_SourceAndAuthor;
    Lab_SourceAndAuthor.hidden = NO;
    
    [IVw_Image setTag:PageNum+Picture_Tag];
    /**
    TVw_description.hidden = NO;
    UIFont *font = [UIFont fontWithName:@"Helvetica" size:16];
    [TVw_description setTextColor:[UIColor colorWithRed:51.0/255.0 green:51.0/255.0 blue:51.0/255.0 alpha:1.0]];
    [TVw_description setFont:font];
    [TVw_description setBackgroundColor:[UIColor clearColor]];
    [TVw_description setScrollEnabled:YES];
    TVw_description.textAlignment = UITextAlignmentLeft;
    [TVw_description setEditable:NO];**/
    
    //Clean Scroll Shadow.
    for (UIView *subview in [WVw_GoogleFeed.scrollView subviews])
        if ([subview isKindOfClass:[UIImageView class]])
            subview.hidden = YES;
    
    WVw_GoogleFeed.delegate = self;
    [WVw_GoogleFeed setOpaque:NO];
    WVw_GoogleFeed.backgroundColor = [UIColor clearColor];
    
    [SV_Detail addSubview:IVw_Logo];
    [SV_Detail addSubview:Lab_SourceAndAuthor];
    [SV_Detail addSubview:IVw_Image];
    [SV_Detail addSubview:WVw_GoogleFeed];
}

#pragma mark UIGestureRecognizerDelegate

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    if ([touch.view isKindOfClass:[UIButton class]])
        return NO;
    return YES;
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
    return YES;
}

#pragma mark EditNotesDelegate

- (void)CancelPressed_EditNotes {
    [Vw_Notes removeFromSuperview];
}

- (void)SetAxisX:(int)AxisX SetAxisY:(int)AxisY SetIndex:(int)Index {
    
    if (Bt_NoteShowOrHide.hidden==YES)
        Bt_NoteShowOrHide.hidden = NO;
    
    UIImage *Image_Note = [UIImage imageNamed:@"notes.png"];
    
    UIButton *Bt_PointNote = [UIButton buttonWithType:UIButtonTypeCustom];
    [Bt_PointNote setImage:Image_Note forState:UIControlStateNormal];
    [Bt_PointNote setFrame:CGRectMake(AxisX-Image_Note.size.width/2, AxisY-Image_Note.size.height/2, Image_Note.size.width, Image_Note.size.height)];
    [Bt_PointNote setTag:Index];
    
    [Bt_PointNote addTarget:self action:@selector(NotesPressed:) forControlEvents:UIControlEventTouchUpInside];
    
    if (SV_Detail==nil)
        [self.WVw_GoogleFeed.scrollView addSubview:Bt_PointNote];
    else
        [self.SV_Detail addSubview:Bt_PointNote];
    
    [Vw_Notes removeFromSuperview];
}

#pragma mark CommentViewDelegate

- (void)uiViewTouched_Comment:(BOOL)wasInSide {
    
    if (!wasInSide) {
        
        [Vw_Comment removeFromSuperview];
        Vw_Comment.MLM_Detail_InBook = nil;
    }
}

#pragma mark UIWebViewDelegate

-(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType {
    if ( inType == UIWebViewNavigationTypeLinkClicked ) {
        [[UIApplication sharedApplication] openURL:[inRequest URL]];
        return NO;
    }
    
    return YES;
}


#pragma mark CreateBookViewDelegate

-(void)uiViewCancel {
    
    [Vw_CreateBook removeFromSuperview];
    self.SV_Detail.userInteractionEnabled = YES;
}

-(void) ViewDidCreated {
    
    [Vw_CreateBook removeFromSuperview];
    
    [self.Vw_addClip initArray:self.AI_accountDetail.MyBoard.BoardArray];
    self.Vw_addClip.Lab_BookName.text = ((AccountBoard *)self.AI_accountDetail.MyBoard.BoardArray.lastObject).name;
    self.Vw_addClip.Row_selected = self.AI_accountDetail.MyBoard.BoardArray.count-1;
    
    //Add Clip view to self.view.
    [UIView animateWithDuration:0.3
                     animations:^{[Vw_addClip setAlpha:1.0];[self.view addSubview:Vw_addClip];}
                     completion:^(BOOL finished){ }];
}

#pragma mark - Function

-(void)CheckMediaInBookPressed {
    
    HomePageViewController *VC_Stream = (HomePageViewController *)self.delegate;
    
    SEMasonryCell *Cell = (SEMasonryCell *)[VC_Stream.SEMv_masonry viewWithTag:[VC_Stream.Array_photos indexOfObject:MLM_detail]+MEDIA_TAG];
    
    //Check Media is in my book.
    if (((UIImageView *)[Cell viewWithTag:IMAGETAG_TAG]).hidden==NO) {
        IVw_Tag.hidden = NO;
        [Bt_SavetoMyboard setImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"clipped" ofType:@"png"]] forState:UIControlStateNormal];
    }
}

- (void)DeScription_WithImage:(int)Image_Description_Length {
    
    if (Check_Description_Index>MLM_detail.text.text_description.length) {
        return;
    }
    
    //http link convert to hyperlink. 
    NSString *regexToReplaceRawLinks = @"(\\b(https?):\\/\\/[-A-Z0-9+&@#\\/%?=~_|!:,.;]*[-A-Z0-9+&@#\\/%=~_|])";
    
    NSError *error = NULL;
    NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:regexToReplaceRawLinks
                                                                           options:NSRegularExpressionCaseInsensitive
                                                                             error:&error];
    NSString *ModifiedString;
    
    
    if (MLM_detail.text.text_description.length>Image_Description_Length) {
                
        int Check_Length = Image_Description_Length;
        
        if (Check_Description_Index+Check_Length<MLM_detail.text.text_description.length) {
            
            NSString *Description_Split = [MLM_detail.text.text_description substringWithRange:NSMakeRange(Check_Description_Index, Check_Length)];
            
            //Check last Letter is or not Character.
            while (![[MLM_detail.text.text_description substringWithRange:NSMakeRange(Check_Description_Index+Check_Length, 1)] isEqualToString:@" "]) {
                
                Description_Split = [MLM_detail.text.text_description substringWithRange:NSMakeRange(Check_Description_Index, Check_Length)];
                
                Check_Length--;
            }
            
            ModifiedString = [regex stringByReplacingMatchesInString:Description_Split
                                                                       options:0
                                                                         range:NSMakeRange(0, [Description_Split length])
                                                                  withTemplate:@"<a href=\"$1\">$1</a>"];
        }
        else
            ModifiedString = [regex stringByReplacingMatchesInString:[MLM_detail.text.text_description substringFromIndex:Check_Description_Index]
                                                             options:0
                                                               range:NSMakeRange(0, [[MLM_detail.text.text_description substringFromIndex:Check_Description_Index] length])
                                                        withTemplate:@"<a href=\"$1\">$1</a>"];

        Check_Description_Index = Check_Description_Index+Check_Length;
    }
    else if (PageNum==0) {
        if (MLM_detail.text.text_description!=nil)
            ModifiedString = [regex stringByReplacingMatchesInString:MLM_detail.text.text_description
                                                             options:0
                                                               range:NSMakeRange(0, [MLM_detail.text.text_description length])
                                                        withTemplate:@"<a href=\"$1\">$1</a>"];
        Check_Description_Index = Check_Description_Index+MLM_detail.text.text_description.length;
    }
    
    [WVw_GoogleFeed loadHTMLString:ModifiedString baseURL:nil];
}

- (void)DescriptionPage:(int)Image_Description_Length {
    
    if (Check_Description_Index>MLM_detail.text.text_description.length) {
        return;
    }
    
    if (((PageNum==MLM_detail.imageArray.count)&&(Image_Description_Length<MLM_detail.text.text_description.length))||(MLM_detail.imageArray.count==0)) {
        
        int Text_Count;
        NSString *Description_Split;
        
        int Check_Description_Length = ONLY_DESCRIPTION_MAX;
        
        //Round Up.
        if((MLM_detail.text.text_description.length-Check_Description_Index)%ONLY_DESCRIPTION_MAX != 0)
            Text_Count = (MLM_detail.text.text_description.length-Check_Description_Index)/ONLY_DESCRIPTION_MAX+PageNum+1;
        else
            Text_Count = (MLM_detail.text.text_description.length-Check_Description_Index)/ONLY_DESCRIPTION_MAX+PageNum;
        
        int Temp_PageNumb = PageNum;
        
        //Split Description.
        for (PageNum = Temp_PageNumb; PageNum<Text_Count; PageNum++) {
            
            //Get Source And Author.
            IVw_Logo = [[UIImageView alloc] initWithImage:IVw_Logo.image];
            IVw_Logo.frame = CGRectMake(ONLY_DESCRIPTION_XAIS_X,
                                        IVw_Logo.frame.origin.y+SCROLLVIEW_HEIGHT*PageNum,
                                        IVw_Logo.image.size.width,
                                        IVw_Logo.image.size.height);
            
            Lab_SourceAndAuthor = [[UILabel alloc] initWithFrame:CGRectMake(IVw_Logo.frame.origin.x+IVw_Logo.frame.size.width+5,
                                                                            IVw_Logo.center.y-21/2,
                                                                            386,
                                                                            21)];
            NSMutableString *NS_SourceAndAuthor = [NSMutableString stringWithString:MLM_detail.NS_Source];
            if (![MLM_detail.NS_Author isEqualToString:@""])
                [NS_SourceAndAuthor appendFormat:@"//%@",MLM_detail.NS_Author];
            Lab_SourceAndAuthor.backgroundColor = [UIColor clearColor];
            Lab_SourceAndAuthor.text = NS_SourceAndAuthor;
            
            IVw_Logo.hidden = NO;
            Lab_SourceAndAuthor.hidden = NO;
            
            //Set Description.
            WVw_GoogleFeed = [[UIWebView alloc]initWithFrame:CGRectMake(ONLY_DESCRIPTION_XAIS_X,
                                                                          DESCRIPTION_VERTICAL_XAIS_Y+SCROLLVIEW_HEIGHT*PageNum,
                                                                          ONLY_DESCRIPTION_WIDTH,
                                                                        ONLY_DESCRIPTION_HEIGHT)];
            //Clean Scroll Shadow.
            for (UIView *subview in [WVw_GoogleFeed.scrollView subviews])
                if ([subview isKindOfClass:[UIImageView class]])
                    subview.hidden = YES;
            
            WVw_GoogleFeed.delegate = self;
            [WVw_GoogleFeed setOpaque:NO];
            WVw_GoogleFeed.backgroundColor = [UIColor clearColor];
            
            //Check Lastest Page.
            if (PageNum+1==Text_Count)
                Description_Split = [MLM_detail.text.text_description substringFromIndex:Check_Description_Index];
            else {
                while (![[MLM_detail.text.text_description substringWithRange:NSMakeRange(Check_Description_Index+Check_Description_Length, 1)] isEqualToString:@" "]) {
                    
                    Description_Split = [MLM_detail.text.text_description substringWithRange:NSMakeRange(Check_Description_Index, Check_Description_Length)];
                    
                    Check_Description_Length--;
                }
            }
            
            Check_Description_Index = Check_Description_Index+Check_Description_Length;
            
            
            //http link convert to hyperlink.
            NSString *regexToReplaceRawLinks = @"(\\b(https?):\\/\\/[-A-Z0-9+&@#\\/%?=~_|!:,.;]*[-A-Z0-9+&@#\\/%=~_|])";
            NSError *error = NULL;
            NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:regexToReplaceRawLinks
                                                                                   options:NSRegularExpressionCaseInsensitive
                                                                                     error:&error];
            if (![Description_Split isEqualToString:@""]) {
                NSString *ModifiedString = [regex stringByReplacingMatchesInString:Description_Split
                                                                           options:0
                                                                             range:NSMakeRange(0, [Description_Split length])
                                                                      withTemplate:@"<a href=\"$1\">$1</a>"];
                [WVw_GoogleFeed loadHTMLString:ModifiedString baseURL:nil];
                [SV_Detail addSubview:WVw_GoogleFeed];
            }
            
            [SV_Detail addSubview:IVw_Logo];
            [SV_Detail addSubview:Lab_SourceAndAuthor];
        }
    }
}

#pragma mark - LoadingUI

-(void)threadStartAnimating {
    
    [self.view addSubview:[LoadingUI LoadingView:self.view.bounds.size.width SetHeight:self.view.bounds.size.height]];
    [self.view addSubview:[LoadingUI LoadingImage:self.view.bounds.size.width SetHeight:self.view.bounds.size.height]];
}

-(void)threadStopAnimating {
    
    [[NSOperationQueue mainQueue] addOperationWithBlock:
     ^(void) {
         [[self.view viewWithTag:LOADINGVIEW_TAG] removeFromSuperview];
         [[self.view viewWithTag:LOADINGIMAGE_TAG] removeFromSuperview];
     }];
}

@end
